package com.test.abc;

import com.alibaba.fastjson2.JSONObject;
import org.apache.commons.lang3.StringUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.TimeUnit;

public class ChatServer {
    public static void main(String[] args) {
        try {
            // 创建ServerSocket对象，指定监听的端口号
            ServerSocket serverSocket = new ServerSocket(6000);

            System.out.println("等待客户端连接...");

            while (true) {
                // 监听客户端的连接请求
                Socket clientSocket = serverSocket.accept();
                System.out.println("客户端已连接");

                // 获取输入流和输出流 输入流和输出流是通过socket对象来进行数据传输的。
                BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
                PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
                String message = in.readLine();
                System.out.println("收到客户端：" + message + "   " + System.currentTimeMillis());
                try {
                    out.println("{\"code\":\"1\",\"data\":{\"data\":{\"address\":\"江苏省\",\"birthday\":\"1900-01-01\",\"expireDate\":\"19001008\",\"gender\":\"男\",\"genderGB\":null,\"id\":\"321200000000000000\",\"issueDate\":\"20001008\",\"issuer\":null,\"name\":\"某某\",\"nation\":\"汉\",\"nationGB\":\"汉\",\"photo\":null},\"type\":\"IDCard\"},\"requestId\":\"TEST01\"}");
                    out.flush();
                } catch (Exception e) {
                    e.printStackTrace();
                    out.println("计算错误");
                }
//                clientSocket.close();
//                System.out.println("客户端断开连接");
            }

        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
